package org.lonetree.tc.webapp.actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.lonetree.tc.core.Book;
import org.lonetree.tc.core.Book.Isbn;
import org.lonetree.tc.core.dao.DAOFactory;

public class AddSource extends SecureAction{

	@Override
	protected ActionForward executeSecure(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception{
		
		try{
			String isbn = request.getParameter("isbn");
			if(isbn == null){
				new NullPointerException("isbn parameter is null").printStackTrace();
				return mapping.findForward("failure");
			}
			
			Book book = (Book)(DAOFactory.getDAOFactory(DAOFactory.FactoryImplementation.DB_DAO_FACTORY).getBookDAO().getBook(new Isbn(isbn)));
			request.setAttribute("book", book);
			return mapping.findForward("success");
		}
		catch(Exception e){
			e.printStackTrace();
			return mapping.findForward("failure");
		}
	}
}
